package com.bl.student.manager.controller.percent;

import com.bl.student.manager.controller.BaseController;
import com.bl.student.common.ApiResponseBody;
import com.bl.student.dao.model.PercentEntity;
import com.bl.student.service.biz.percent.PercentService;
import com.bl.student.service.biz.point.PointService;
import com.bl.student.service.vo.DelBody;
import com.bl.student.service.vo.point.PointModVo;
import com.bl.student.service.vo.point.PointTypeListVo;
import com.bl.student.service.vo.teacher.TeacherListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.math.BigDecimal;

@RequestMapping(value = {"/student/manager/percent"})
@Api(value = "抽成比例相关api", description = "抽成比例相关api")
@Log4j2
@RestController
public class PercentController extends BaseController {
    @Autowired
    PercentService percentService;

    @ApiOperation(value = "修改抽成比例", notes = "修改抽成比例 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/mod"})
    public ApiResponseBody modify(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        percentService.changePercent(body.getId());

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "查看当前抽成比例", notes = "查看当前抽成比例")
    @ApiImplicitParams({})
    @GetMapping(value = {"/get"})
    public ApiResponseBody<BigDecimal> getPercent(HttpServletRequest request) {

        BigDecimal percent = percentService.getPercentInfo();

        return ApiResponseBody.createSuccessBody(percent);
    }

}
